import React from 'react';
import {Form, Input, Button, Typography} from 'antd';

import "./index.less"
import common from "../../common";

const {Title} = Typography;


function Login(props) {

    const onFinish = (values) => {
        common.ajax("post", "/passport/token/create", values).then(res => {
            common.setToken(res.token)
            common.ajax("get", "/passport/user/whoami").then(res => {
                window.localStorage.setItem("user", JSON.stringify(res))
                common.toast("登录成功")
                props.history.push('/')

            })
        })
    };

    return (
        <div className="Login">
            <div className="img"/>
            <div className="title">
                <Title level={2}>迅腾生产管理系统</Title>
            </div>
            <div className="logoTop"/>
            <div className="loginLeft">
                <div className="logoLeft"/>
            </div>

            <div className="loginRight">
                <div className="loginFrom">
                    <Form name="basic" labelCol={{span: 8}}
                          wrapperCol={{span: 16}}
                          onFinish={onFinish}>
                        <Form.Item label="用户名" name="mobile"
                                   rules={[{required: true, message: '请输入你的用户名!'}]}>
                            <Input/>
                        </Form.Item>
                        <Form.Item label="密码" name="password"
                                   rules={[{required: true, message: '请输入你的密码!'}]}>
                            <Input.Password/>
                        </Form.Item>
                        <Form.Item wrapperCol={{offset: 8, span: 16}}>
                            <Button type="primary" htmlType="submit">
                                登录
                            </Button>
                        </Form.Item>
                    </Form>
                </div>
            </div>
            <div className="clear"/>
        </div>

    );
}

export default Login;